package cn.lj.service;

import cn.lj.dao.IProductDao;
import cn.lj.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ProductService {

    @Autowired
    private IProductDao productDao;

    public void save(Product product) {
        productDao.save(product);
    }

    public void delProduct(int id) {
        productDao.delProduct(id);
    }

    public void update(Product product) {
        productDao.update(product);
    }

    public Product findById(Integer id) {
        return productDao.findById(id);
    }

    public List<Product> findAll() throws Exception {
        return productDao.findAll();
    }


    public List<Product> findAllByName(String productName) {
        return productDao.findAllByName("%" + productName +"%");
    }
}
